//
//  GYZHot_countryCollectionViewCell.m
//  Qyer
//
//  Created by GYz on 15/10/19.
//  Copyright © 2015年 GF. All rights reserved.
//

#import "GYZHot_countryCollectionViewCell.h"
@implementation GYZHot_countryCollectionViewCell

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.photo = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH/7*3.1, SCREEN_WIDTH/7*4.4)];
        [self.contentView addSubview:self.photo];
        
        UIImageView *backView = [[UIImageView alloc]initWithFrame:CGRectMake(0, self.photo.frame.size.height - 60, SCREEN_WIDTH/7*3.1, 60)];
        [backView setImage:[UIImage imageNamed:@"backViewCell"]];
        [self.contentView addSubview:backView];
        
        self.countLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 5, SCREEN_HEIGHT / 18)];
        self.countLabel.backgroundColor = [UIColor colorWithRed:0. green:0. blue:0. alpha:.3];
        self.countLabel.textAlignment = YES;
        self.countLabel.font = [UIFont systemFontOfSize:23.];
        self.countLabel.textColor = [UIColor whiteColor];
        [self.contentView addSubview:self.countLabel];
        
        self.label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 5, SCREEN_HEIGHT / 18)];
        self.label.backgroundColor = [UIColor colorWithRed:0. green:0. blue:0. alpha:.3];
        self.label.textAlignment = YES;
        self.label.font = [UIFont systemFontOfSize:15.];
        self.label.textColor = [UIColor whiteColor];
        [self.contentView addSubview:self.label];
        
        self.cnnameLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, self.photo.frame.size.height - 50, 220, 20)];
        self.cnnameLabel.textColor = [UIColor whiteColor];
        [self.contentView addSubview:self.cnnameLabel];
        
        self.ennameLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, self.photo.frame.size.height - 30, 220, 20)];
        self.ennameLabel.font = [UIFont systemFontOfSize:13.];
        self.ennameLabel.textColor = [UIColor whiteColor];
        [self.contentView addSubview:self.ennameLabel];
    }
    return self;
}

- (void)setValueWithModel:(GYZHot_countryModel *)model
{
    [self.photo sd_setImageWithURL:[NSURL URLWithString:model.photo] placeholderImage:[UIImage imageNamed:@"zhanweiPic.png"]];
    self.countLabel.text = model.count.stringValue;
    self.label.text = model.label;
    self.cnnameLabel.text = model.cnname;
    self.ennameLabel.text = model.enname;
    
    // 右上角自适应
    CGFloat countWidth = [StringWithWidth widthWithText:self.countLabel.text height:SCREEN_HEIGHT / 18 font:kFont(23.0)];
    CGFloat labelWidth = [StringWithWidth widthWithText:self.label.text height:SCREEN_HEIGHT / 18 font:kFont(23.0)];
    // 取两者中大的
    CGFloat max = countWidth > labelWidth ? countWidth : labelWidth;
    self.countLabel.frame = CGRectMake(self.photo.frame.size.width - max - 10, 5, max, SCREEN_HEIGHT / 18);
    self.label.frame = CGRectMake(self.photo.frame.size.width - max - 10, 5 + SCREEN_HEIGHT / 18, max, SCREEN_HEIGHT / 18);
}

@end
